package org.jberney.wvdexporter.video;

import java.nio.ByteBuffer;

public class WvdFrameHeader {

	public static final int LENGTH = 8;

	private long duration;
	private short width;
	private short height;
	private int frameLength;
	private byte framerate;

	public WvdFrameHeader(byte[] headerBytes) {

		ByteBuffer durationByteBuffer = ByteBuffer.allocate(4);
		for (int i = 0; i < 4; i++) {
			durationByteBuffer.put(headerBytes[3 - i]);
		}
		this.duration = durationByteBuffer.getInt(0);
		this.width = (short) (((headerBytes[5] & 0x0F) << 8) | headerBytes[4]);
		this.height = (short) ((headerBytes[6] << 4) | ((headerBytes[5] & 0xF0) >>> 4));
		this.frameLength = 3 * this.width * this.height / 2;
		this.framerate = headerBytes[7];

	}

	public long getDuration() {
		return this.duration;
	}

	public short getWidth() {
		return this.width;
	}

	public short getHeight() {
		return this.height;
	}

	public int getFrameLength() {
		return this.frameLength;
	}

	public byte getFramerate() {
		return this.framerate;
	}

}
